import React,{Component} from 'react';
import {LoginBox} from './style'
import {Form, Icon, Input, Button, Checkbox,} from 'antd';
import {connect} from 'dva'
import 'antd/dist/antd.css'
import imgsrc from '../../static/images/touxiang.jpeg'
class Login extends Component{
    constructor(){
        super();
        this.state = {
            username:'',
            password:'',
        }
    }
    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
          if (!err) {
            console.log('Received values of form: ', values);
          }
        });
      }
      doLogin(){
        // console.log('发送action');
        // console.log(this.state.username);
        // console.log(this.state.password);
        let {username,password} = this.state;
            this.props.dispatch({type:'teacher/doLogin',payload:{
                username:username,
                password:password,
            }})
      }
    render(){
        const { getFieldDecorator } = this.props.form;
        return(
            <LoginBox>
                <img src={imgsrc}></img>
                <Form onSubmit={this.handleSubmit} className="login-form">
                    <Form.Item>
                    {getFieldDecorator('userName', {
                        rules: [{ required: true, message: 'Please input your username!' }],
                    })(
                        <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" onChange={e=>{this.setState({username:e.target.value})}}/>
                    )}
                    </Form.Item>
                    <Form.Item>
                    {getFieldDecorator('password', {
                        rules: [{ required: true, message: 'Please input your Password!' }],
                    })(
                        <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" onChange={e=>{this.setState({password:e.target.value})}}/>
                    )}
                    </Form.Item>
                    <Form.Item>
                    {getFieldDecorator('remember', {
                        valuePropName: 'checked',
                        initialValue: true,
                    })(
                        <Checkbox>Remember me</Checkbox>
                    )}
                    <a className="login-form-forgot" href="">Forgot password</a>
                    <Button type="primary" htmlType="button" className="login-form-button" onClick={e=>{this.doLogin()}}>
                        Log in
                    </Button>
                    Or <a href="">register now!</a>
                    </Form.Item>
                </Form>
            </LoginBox>
        )
    }
}
const WrappedNormalLoginForm = Form.create({ name: 'normal_login' })(Login);
const mapStateProps = (state)=>{
    return{

    }
}
export default connect(mapStateProps)(WrappedNormalLoginForm)
